﻿using System;
using Autofac;
using GC_VKMD.MusicDownloaderClient.Abstractions.Factories;
using GC_VKMD.MusicDownloaderClient.Abstractions.Interfaces.Helpers;
using GC_VKMD.MusicDownloaderClient.Abstractions.Interfaces.Managers;
using GC_VKMD.MusicDownloaderClient.Factories;
using GC_VKMD.MusicDownloaderClient.Helpers;
using GC_VKMD.MusicDownloaderClient.Managers;

namespace GC_VKMD.MusicDownloaderClient.Modules.Autofac
{
	public class MusicDownloaderClientModule : Module
	{
		#region Override Methods

		protected override void Load(ContainerBuilder builder)
		{
			base.Load(builder);

			var uri = new Uri(GetType().Assembly.GetName().CodeBase);
			builder.RegisterType<ApplicationConfiguration>().As<IApplicationConfiguration>()
				.WithParameter(
					(p, c) => p.ParameterType == typeof(string),
					(p, c) => uri.LocalPath)
				.SingleInstance();

			builder.RegisterType<BrowserDialog>().As<IBrowserDialog>().SingleInstance();

			//Dependencies: IBrowserDialog, IApplicationConfiguration
			builder.RegisterType<WindowViewModelFactories>().As<WindowViewModelBaseFactories>().SingleInstance();

			builder.RegisterType<WindowFactory>().As<WindowBaseFactory>().SingleInstance();

			//Dependencies: WindowBaseFactory, WindowViewModelBaseFactories
			builder.RegisterType<WindowAdapterFactory>().As<WindowAdapterBaseFactory>().SingleInstance();

			//Dependencies: WindowAdapterBaseFactory
			builder.RegisterType<WindowManager>().As<IWindowManager>().SingleInstance();
		}

		#endregion
	}
}
